package com.qdu.servlet;


import com.qdu.entity.Journal;
import com.qdu.entity.User;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.qdu.service.JournalService;
import com.qdu.service.impl.JournalServiceImpl;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Lenovo
 */
@WebServlet("/ands")
public class AddNewDiaryServlet extends HttpServlet {

    JournalService journalService = new JournalServiceImpl();
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {               
        req.setCharacterEncoding("utf-8");
        SimpleDateFormat df = new SimpleDateFormat("HHmmss");//设置日期格式为随机Jid
        System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        
        String Jid=df.format(new Date());

        User user=new User();
        HttpSession session=req.getSession();
        user=(User)session.getAttribute("user");
        int id=user.getId();
        System.out.println("addj当前登录id："+id);
        
        String title = req.getParameter("diaryTitle");
        String content = req.getParameter("diaryContent");
        
        System.out.println("--------------------------------------------------");
        System.out.println(title);
        System.out.println(content);
             
        Journal jon=new Journal(Jid,id,title,content); 
        System.out.println(Jid);
        journalService.publishJournal(jon);
    }
}
 